﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using BomberManServer.Gaming.Socket;

namespace BomberManServer.Gaming.Object
{
    public class Match
    {
        // different types : 1v1, 2v2, 1v1v1v1
        public enum MatchType : ushort { SOLO, TEAM, FFA };

        // Game uid for webservice
        public ushort uid { get; private set; }
        // the match type
        public MatchType type { get; private set; }
        public List<Team> teams { get; private set; }
        // listing all players in this game
        public List<Player> players { get; private set; }


        // create the message
        public MemoryStream stream { get; private set; }

        // contructor called by WebService parser
        public Match(UInt16 uid, MatchType type)
        {
            this.uid = uid;
            this.type = type;
            this.players = new List<Player>();
            teams = new List<Team>();
        }

        // add a team to the match
        public void add(Team team) {
            teams.Add(team);
            foreach (Player player in team.players)
            {
                player.id = Convert.ToUInt16(players.Count);
                players.Add(player);
            }
        }

        public List<Player> getPlayerNotFromTeamID(UInt16 id)
        {
            List<Player> lplayer = new List<Player>();
            foreach (Team team in teams)
            {
                if (team.id != id)
                    foreach (Player player in team.players)
                        lplayer.Add(player);
            }
            return lplayer;
        }

        public List<Player> getAlivePlayers()
        {
            List<Player> aPlayers = new List<Player>();
            foreach(Player player in players)
            {
                if(player.avatar.isAlive)
                    aPlayers.Add(player);
            }
            return aPlayers;
        }

    }
}
